	#pragma once

#include "OffscreenView.h"
#include "PanTool.h"
								
class PanView : public OffscreenView
{
	friend class PanTool;

protected:
	PanView();           // protected constructor used by dynamic creation

// Attributes
protected:
	CSize				m_BenchSize;
	CSize				m_Size;
	int					m_Gap;
	CPoint				m_Origin;
	mutable PanTool		m_ToolPan;
	COLORREF			m_BackgroundColor;

public:
	PanTool * GetPanTool() const
		{ return &m_ToolPan; }			   

	CPoint GetOrigin() const
		{ return m_Origin; }

	CSize GetBenchSize() const
		{ return m_BenchSize; }
	bool IsBenchEmpty() const
		{ return m_BenchSize.cx == 0 && m_BenchSize.cy == 0; }

	int GetGap() const
		{ return m_Gap; }

	CSize GetClientSize() const;

	virtual void PreSetScrollInfo(UINT, LPSCROLLINFO) { }

	virtual void OnResizeBench() { }
	virtual void OnPan() { }

public:

	CPoint ClientToBench(CPoint p) const;
	CPoint BenchToClient(CPoint p) const;
	CRect ClientToBench(CRect r) const;
	CRect BenchToClient(CRect r) const;
	CRect BenchRect() const;

	void InvalidateBench();
	void InvalidateBorder();

	virtual COLORREF GetBackgroundColor() const
		{ return m_BackgroundColor; }
	virtual void SetBackgroundColor(COLORREF c);

protected:
	virtual bool AllowPaintOnBackground() const
		{ return true; } //brush tool, for example, paints its circle over the background

protected:
	void EraseBackground(CDC * pDC, const CRgn &);
	virtual void DoPaint(CDC * pDC, const CRgn &);

// Operations
protected:	   

	void SetGap(int gap);

	void SetOrigin(CPoint p, bool bInvalidate = false);
	void SetOrigin(int x, int y, bool bInvalidate = false)
		{ SetOrigin(CPoint(x, y), bInvalidate); }

	void ResizeBench(CSize s);
	void ResizeBench(int cx, int cy)
		{ ResizeBench(CSize(cx, cy)); }

	virtual void PaintRect(CDC * pDC, const CRect & rect) = 0;

	virtual void UpdateScrollBars();

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(PanView)
protected:
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
	//}}AFX_VIRTUAL

// Implementation
protected:
	virtual ~PanView();

protected:
	virtual int HandleCreate(LPCREATESTRUCT lpCreateStruct);
	virtual void HandleSize(UINT nType, int cx, int cy);
	virtual void HandleHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
	virtual void HandleVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
public:
	DECLARE_MESSAGE_MAP()
	afx_msg void OnToolPan();
	afx_msg void OnUpdateToolPan(CCmdUI *pCmdUI);
};

//{{AFX_INSERT_LOCATION}}
